<script type="text/javascript">
	var form_url = '/weixin/menu/add' ;
	$(function() {
		
		$('#ct-menu').combotree({
			method: 'get', url:'/weixin/menu/list', editable: false, value: '${pid!}',
			icons:[{iconCls:'icon-clear', handler: function(e){ $(e.data.target).combotree('clear'); }}]
		});
		
		$('#responseType').combobox({
			method: 'get', url:'/weixin/dict/response_type_commonbox',
			editable: false, panelHeight:'auto', textField:'name', valueField:'value'
		});
		
		var inputUrl = $('#url').textbox();
		var inputChoose = $('#choose').combobox().combobox('disable');
		
		$('#ct-type').combobox({
			editable: false, panelHeight:'auto', textField:'lable', valueField:'value', value: 'click',
			data: [
			       {lable: '点击事件', value: 'click'}, 
			       {lable: '跳转URL', value: 'view'}, 
			       {lable: '扫描事件', value: 'scancode_push'}, 
			       {lable: '扫描同步信息事件', value: 'scancode_waitmsg'},
			       {lable: '弹出系统拍照发图', value: 'pic_sysphoto'},
			       {lable: '弹出微信相册发图器', value: 'pic_weixin'},
			       {lable: '弹出拍照或者相册发图', value: 'pic_photo_or_album'},
			       {lable: '地理位置', value: 'location_select'}
			],
			onChange: function(newValue, oldValue){
	            if(newValue == 1) {
	            	inputUrl.textbox('disable');
	            	inputChoose.combobox('enable');
	            	$('#ct-menu').combobox('disable');
	            	$('#leaf').combobox('setValue', 0).combobox('readonly');
	            } else if(newValue == 2) {
	            	inputUrl.textbox('disable');
	            	inputChoose.combobox('disable');
	            	$('#ct-menu').combobox('enable');
	            	$('#leaf').combobox('setValue', 0).combobox('readonly');
	            } else if(newValue == 3) {
	            	inputUrl.textbox('enable');
	            	inputChoose.combobox('disable');
	            	$('#ct-menu').combobox('enable');
	            	$('#leaf').combobox('setValue', 1).combobox('readonly');
	            } else if(newValue == 4) {
	            	inputUrl.textbox('enable');
	            	inputChoose.combobox('disable');
	            	$('#ct-menu').combobox('enable');
	            	$('#leaf').combobox('setValue', 1).combobox('readonly');
	            }
	        }
		});
		
		$('#response-type').combobox({
			editable: false, panelHeight:'auto', textField:'lable', valueField:'value', value: 'none',
			data: [
			       {lable: '无响应', value: 'none'}, 
			       {lable: '文本', value: 'text'}, 
			       {lable: '其他', value: 'other'}
			]
		});
		
		if(null != "" && "${id!}" != "") {
			form_url = '/weixin/menu/update' ;
			$.get('/weixin/menu/get/${id!}', function(result) {
				try {
					$('#form').form('load', result);
				} catch(e) {
					$.easyui.loaded(); console.error(e) ;
				}
			}, 'JSON').complete(function(){$.easyui.loaded();});
		}		
	});
	
	function submitForm() {
		var checkform = $('#form').form('validate');
		if(checkform) {
			$.easyui.loading();
			$.post(form_url, MM.getData('#form', true), function(result) {
				try {
					if(result.code == 200) {
						$obj.reload();$window.window('close');alertify.success(result.message);
					} else {
						$.messager.alert('提示信息', result.message, 'warning') ;
					}
				} catch(e) {
					$.easyui.loaded(); console.error(e) ;
				}
			}, 'JSON').complete(function(){$.easyui.loaded();});
		}
	}
</script>

<div class="easyui-panel form-panel" data-options="border: false, fit: true">
	<form id="form" method="post">
		<input type="hidden" name="id" value="${id!}">
		<table class="table-form">
			<tr>
				<th>父级菜单：</th>
				<td><input id="ct-menu" name="parentId" style="width:180px;"></td>
				<th>菜单状态：</th>
				<td>
					<select class="easyui-combobox" name="status" style="width:180px;" data-options="required:true, editable: false, panelHeight:'auto'">
		                <option value="1">正常</option>
		                <option value="0">禁用</option>
		            </select>
				</td>
			</tr>
			<tr>
				<th>菜单名称：</th>
				<td><input class="easyui-textbox" name="name" style="width:180px" data-options="required:true,validateOnCreate:false,validateOnBlur:true"></td>
				<th>菜单类型：</th>
				<td><input id="ct-type" name="eventType" style="width:180px;"></td>
			</tr>
			<tr>
				<th>唯一标识：</th>
				<td><input class="easyui-textbox" name="eventKey" data-options="prompt: '默认自动生成'" style="width:180px"></td>
				<th>菜单排序：</th>
				<td><input class="easyui-numberbox" name="orderNum" value="100" style="width:180px" data-options="min:100, max: 9999,required:true,validateOnCreate:false,validateOnBlur:true"></td>
			</tr>
			<tr>
				<th>响应类型：</th>
				<td><input id="responseType" name="responseType" style="width:180px;"></td>
			</tr>
			<tr>
				<th>URL地址：</th>
				<td colspan="3"><input id="url" name="url" style="width:464px"></td>
			</tr>
			<tr>
				<th>响应内容：</th>
				<td colspan="3"><input class="easyui-textbox" name="content" style="width:100%;height:60px" data-options="prompt: '', multiline:true"></td>
			</tr>
			<tr>
				<th>备注信息：</th>
				<td colspan="3"><input class="easyui-textbox" name="remarks" style="width:100%;height:60px" data-options="multiline:true"></td>
			</tr>
		</table>
	</form>
</div>

<div class="submit-toolbar" id="footer"  style="border-bottom: 0;border-left: 0;border-right: 0;">
	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="submitForm()" style="width:80px">提交</a>
	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="MM.closeCurrentWindow()" style="width:80px">关闭</a>
</div>

